<?php
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of ModReport
 *
 * @author Bryan Cruz
 */
class ModReport {

    public $defaultReport;
    public $lastQuery;
    public $instanceName = "ModReport";
    public $db;
    public $reports = array();
    public $printers = array("excel" => array("name" => "EaExcelPrinter",
            "label" => "Excel"));

    /*        "pdf" => array("name" => "EaHtml2PdfPrinter",
      "label" => "Pdf") */

    function __construct() {
        
        
        $repEstadoCuotas = new RepEstadoCuotas();
        $repEstadoCuotas->key = "rpt_estadoCuotas";
        $this->addReport($repEstadoCuotas);
        
        $repCheques = new RepCheques();
        $repCheques->key = "rpt_cheques";
        $this->addReport($repCheques);

        $repFactDetallada = new RepFacturaDetallada();
        $repFactDetallada->key = "rpt_factDetallada";
        $this->addReport($repFactDetallada);

        $repFactDiaria = new RepFacturaDiaria();
        $repFactDiaria->key = "rpt_factDiaria";
        $this->addReport($repFactDiaria);

        $repStudCatedratico = new RepStudCatedratico();
        $repStudCatedratico->key = "rpt_studCatedratico";
        $this->addReport($repStudCatedratico);

        $repStudCarrera = new RepStudCarrera();
        $repStudCarrera->key = "rpt_studCarrera";
        $this->addReport($repStudCarrera);

        $repStudInactCiclo = new RepStudInactCiclo();
        $repStudInactCiclo->key = "rpt_studInactCiclo";
        $this->addReport($repStudInactCiclo);
    }

    public function getCssFiles() {
        ?>
        <link rel="stylesheet" href="../../../bootstrap/css/bootstrap.css"/>
        <?php
    }

    public function getJsFiles() {
        
    }

    public function getWindowTitle() {
        return "Reportes";
    }

    /**
     * 
     * @param type $query
     * @param type $pkField
     * @param type $descField
     */
    public function getListJson($query, $pkField, $descField) {
        $r = $this->db->queryToArray($query);
        $j = array();
        foreach ($r as $rws) {
            array_push($j, array("id" => $rws[$pkField], "value" => $rws[$pkField] . "-" . $rws[$descField]));
        }
        echo json_encode($j);
    }

    private function addReport($rep) {
        $this->reports[$rep->key] = $rep;
    }

    public function main() {
        $name = getParam("name");
        $this->defaultReport = $this->reports[$name];
        $this->defaultReport->db = $this->db;
        switch (getParam("print")) {
            case "true": {
                    $pri = getParam("printer");
                    $idrep = getParam("name");
                    $printer = new $pri();
                    if ($this->defaultReport->key == $idrep) {
                        $printer->db = $this->db;
                        $printer->write($this->defaultReport);
                        break;
                    }
                    break;
                }
            default:
                if (isEmpty(getParam("params"))) {
                    include "mainreporte.php";
                } else {
                    include "resultreporte.php";
                }
                break;
        }
    }

}
?>
